 begintownscript;	

 variables;
int i,j,k,r1,choice;
short weapon,x,y;
string dlgstr,char1;
body;
beginstate INIT_STATE;

	set_name(7,"Gar");
	set_name(8,"Bar");
	set_name(9,"Captain Carlington");

	add_char_to_group(7,1);
	add_char_to_group(8,1);
	add_char_to_group(11,1);

	if (get_flag(6,6) == 6)
		erase_char(9);

	if (get_flag(3,0) == 10)
		erase_char(10);
	 break;	
beginstate START_STATE;
break;	

beginstate EXIT_STATE;

break;

beginstate 10;
	if (get_flag(3,0) == 0) {
		set_flag(3,0,1);
		reset_dialog();
		add_dialog_str(0,"Unbeliavable. You turn a corner and discover a bandit sleeping on a chair. He mumbles something in his sleep and smiles happily. You creep close to him and...",0);
		add_dialog_choice(0,"... take his weapons and interrogate him.");
		add_dialog_choice(1,"... kill him.");
		choice = run_dialog(1);

		if (choice == 1) {
			reset_dialog();
			add_dialog_str(0,"You gingerly remove the man of his weapons. He is so fast asleep that he does not notice a thing. This next part he does notice and it is a very unpleasant way to wake up.",0);
			add_dialog_str(1,"You grab the man and place him firmly in a headlock. As he wakes up you squeeze him tighter to show you mean business. _Wh...? Help!_ The man grunts and when he fully understands the situation: _Don't kill me!_",0);
			add_dialog_str(2,"What do you ask of him?",0);
			add_dialog_choice(0,"Where's captain Carlington?");
			add_dialog_choice(1,"Where's the gold?");
			choice = run_dialog(1);
			
			if (choice == 1) {
				set_flag(3,0,2);
				set_state_continue(14);
}			
			if (choice == 2) {
				set_flag(3,0,3);
				set_state_continue(14);
}
}
	
		if (choice == 2) {
			play_sound(29);
			message_dialog("You are a brutal, brutal human being.","");
			kill_char(10,0,2);
			set_flag(3,0,10);
}
}

		if (character_in_party(203) >= 4) {
			block_entry(1);
			message_dialog("_Surely we're not leaving now!_ Carlington calls out. _The leader of the bandits is in a room to the south. We must have his head so that my platoon may rest in peace._","");
}
 break;

beginstate 11;
	if (get_flag(3,11) == 0) {
		set_flag(3,11,1);
		alert_char(1001);
		if (character_in_party(203) >= 4) {
			reset_dialog();
			add_dialog_str(0,"You've come face to face with the leader of the bandits. He is a vicious looking man in a plate mail and he wields a massive claymore. He stops his conversation with the woman in wizard's robes when you enter the room.",0);
			if (party_size() == 1) {
			change_char_health(0,-500);
				append_string("He gazes at you looking nonplussed. His eyes fall on captain Carlington and he smiles. _Why my good captain, what have you brought for me this time?_ The captain stabs ");
				clear_buffer();
				append_char_name(0);
				append_string(" in the back.");
				get_buffer_text(dlgstr);
}
			if (party_size() == 2) {
			change_char_health(1,-500);
				append_string("He gazes at you looking nonplussed. His eyes fall on captain Carlington and he smiles. _Why my good captain, what have you brought for me this time?_ The captain stabs ");
				append_char_name(1);
				append_string(" in the back.");
				get_buffer_text(dlgstr);
}
			if (party_size() == 3) {
			change_char_health(2,-500);
				append_string("He gazes at you looking nonplussed. His eyes fall on captain Carlington and he smiles. _Why my good captain, what have you brought for me this time?_ The captain stabs ");
				append_char_name(2);
				append_string(" in the back.");
				get_buffer_text(dlgstr);
}
			if (party_size() == 4) {
			change_char_health(3,-500);
				append_string("He gazes at you looking nonplussed. His eyes fall on captain Carlington and he smiles. _Why my good captain, what have you brought for me this time?_ The captain stabs ");
				append_char_name(3);
				append_string(" in the back.");
				get_buffer_text(dlgstr);
}
			add_dialog_str(1,dlgstr,0);
			add_dialog_str(2,"Fortunately the wound is not fatal. _Just a bunch of do-gooders, Darren._ Carlington says. _I say we kill them now and get on with robbing the good people of Tonstville._ The bandit leader grins. _A wondrous idea!_",0);
			add_dialog_str(3,"_Gar! Bar!_ The two massive ogres on your either side advance on you.",0);
			run_dialog(1);
			x = char_loc_x(4);
			y = char_loc_y(4);
			remove_char_from_party(203);
			spawn_creature(9);
			relocate_character(9,x,y);
			force_instant_terrain_redraw();
			set_attitude(9,10);
			end();
}
		if (character_in_party(203) == -1) {
			reset_dialog();
			add_dialog_str(0,"You've come face to face with the leader of the bandits. He is a vicious looking man in a plate mail and he wields a massive claymore. He stops his conversation with the woman in wizard's robes when you enter the room.",0);
			add_dialog_str(1,"He gives you a brief questioning glare and shrugs. _Looks like some of the world-savers escaped. Gar! Bar! Kill 'em!_ The two massive ogres on your either side advance on you.",0);
			run_dialog(1);
}
}

 break;

beginstate 12;
	if (get_flag(3,1) == 0) {
		set_flag(3,1,1);
		begin_talk_mode(1);
}
 break;

beginstate 13;

	if (get_flag(3,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"A tome lies on the pedestal. You know enough about magic to know when you see a magical item, and this certainly is one. You open the tome only to discover that you can't immediately read the runes.",0);
		add_dialog_str(1,"As is the way of wizards, whoever wrote this book wrote it in code so that rival mages could not benefit from their wisdom. Will you take some time to try and decipher the runes?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");
		choice = run_dialog(1);
		
	
	if ((choice == 1) && (get_skill_total(42) >= 16)) {

		set_flag(3,2,1);

		message_dialog("You manage to decipher the runes on the tome. They instruct you how to call lightning from the skies to rain death on your enemies.","");
		clear_buffer();
		reset_dialog();
		append_char_name(0);
		if ((get_stat(0,11) >= 8) && (get_spell_level(0,0,10) > 0) && (get_spell_level(0,0,10) < 4)) {
			append_string(" improves his knowledge in the lightning spray spell.");
			change_spell_level(0,0,10,1);
}
		if ((get_stat(0,11) >= 8) && (get_spell_level(0,0,10) == 0)) {
			append_string(" learns a new spell: lightning spray.");
			change_spell_level(0,0,10,1);
}
		if ((get_stat(0,11) >= 8) && (get_spell_level(0,0,10) >= 4))
			append_string(" learns nothing new from the tome.");
		if (get_stat(0,11) < 8)
			append_string(" does not know enough about magic to learn anything.");
		get_buffer_text(char1);
		add_dialog_str(0,char1,0);
		clear_buffer();
		append_char_name(1);
		if ((get_stat(1,11) >= 8) && (get_spell_level(1,0,10) > 0) && (get_spell_level(1,0,10) < 4)) {
			append_string(" improves his knowledge in the lightning spray spell.");
			change_spell_level(1,0,10,1);
}
		if ((get_stat(1,11) >= 8) && (get_spell_level(1,0,10) == 0)) {
			append_string(" learns a new spell: lightning spray.");
			change_spell_level(1,0,10,1);
}
		if ((get_stat(1,11) >= 8) && (get_spell_level(1,0,10) >= 4))
			append_string(" learns nothing new from the runes.");
		if (get_stat(1,11) < 8)
			append_string(" does not know enough about magic to learn anything.");
		get_buffer_text(char1);
		if (char_ok(1) == TRUE)
			add_dialog_str(1,char1,0);
		clear_buffer();
		append_char_name(2);
		if ((get_stat(2,11) >= 8) && (get_spell_level(2,0,10) > 0) && (get_spell_level(2,0,10) < 4)) {
			append_string(" improves his knowledge in the lightning spray spell.");
			change_spell_level(2,0,10,1);
}
		if ((get_stat(2,11) >= 8) && (get_spell_level(2,0,10) == 0)) {
			append_string(" learns a new spell: lightning spray.");
			change_spell_level(2,0,10,1);
}
		if ((get_stat(2,11) >= 8) && (get_spell_level(2,0,10) >= 4))
			append_string(" learns nothing new from the runes.");
		if (get_stat(2,11) < 8)
			append_string(" does not know enough about magic to learn anything.");
		get_buffer_text(char1);
		if (char_ok(2) == TRUE)
			add_dialog_str(2,char1,0);
		clear_buffer();
		append_char_name(3);
		if ((get_stat(3,11) >= 8) && (get_spell_level(3,0,10) > 0) && (get_spell_level(3,0,10) < 4)) {
			append_string(" improves his knowledge in the lightning spray spell.");
			change_spell_level(3,0,10,1);
}
		if ((get_stat(3,11) >= 8) && (get_spell_level(3,0,10) == 0)) {
			append_string(" learns a new spell: lightning spray.");
			change_spell_level(3,0,10,1);
}
		if ((get_stat(3,11) >= 8) && (get_spell_level(3,0,10) >= 4))
			append_string(" learns nothing new from the runes.");
		if (get_stat(3,11) < 8)
			append_string(" does not know enough about magic to learn anything.");
		get_buffer_text(char1);
		if (char_ok(3) == TRUE)
			add_dialog_str(3,char1,0);
		run_dialog(1);
}
	if ((choice == 1) && (get_skill_total(42) < 16))
		message_dialog("Try as you might you cannot figure out what the tome is about. If only you were better at reading runes.","");
}
 break;

 beginstate 14;
	if (get_flag(3,0) == 2) {
		message_dialog("_Go down the hall and turn west... to your right. When you're walking turn to your right! He's in there!_ You thank the man by knocking him unconscious.","");
		erase_char(10);
		set_flag(3,0,10);
}
	if (get_flag(3,0) == 3) {
		message_dialog("_Go down the hall and turn west... to your right. When you're walking turn to your right! The gold's in a chest in secret room!_ You thank the man by knocking him unconscious.","");
		erase_char(10);
		set_flag(3,0,10);
}
 break;

 beginstate 15;
	if (get_flag(3,3) == 0) {
		set_flag(3,3,1);
		clear_buffer();
		append_string("There is precisely ");
		append_number((get_flag(99,9) * 100) + get_flag(99,10));
		append_string(" gold in the chest.");
		get_buffer_text(dlgstr);
		message_dialog("This chest holds a surprisingly large amount of money. In fact you could swear that it is the exact same amount you had before the bandits captured you.",dlgstr);
		change_coins(get_flag(99,9) * 100);
		change_coins(get_flag(99,10));
}
 break;

 beginstate 20;
	reset_dialog();
	add_dialog_str(0,"You find stairs. Shall you desend?",0);
	add_dialog_choice(0,"Yay!");
	add_dialog_choice(1,"Nay!");
	choice = run_dialog(1);
	if (choice == 1)
		move_to_new_town(0,18,26);
 break;